package com.thinker.plantForm.controller;

import com.github.pagehelper.Page;
import com.thinker.plantForm.model.Users;
import com.thinker.plantForm.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.jvm.hotspot.utilities.Assert;
import tk.mybatis.mapper.entity.Example;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by hezi on 2017/9/8.
 */
@Controller
@RequestMapping("/users")
public class UsersController {

    @Autowired
    private UsersService usersService;

    @RequestMapping(value = "/select/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Object select(HttpServletRequest request, @PathVariable int id) {
        List list = this.usersService.selectPage(id,3);
        return list;
    }

    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ResponseBody
    public Object selectByExample() {
        Example example = new Example(Users.class);
        example.createCriteria().andGreaterThan("id", 3);
        example.setCountProperty("username");
        //总数
        return this.usersService.selectByExample(example);
    }
}
